using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using SMS.Framework;
using SMS.Common;

namespace SMS.DataPackingWindow
{
    public class DataPackingWindow : IMdiChildWindow
    {
        private PackForm _PackFormInstance;

        public DataPackingWindow()
        {
            Context.Current.OnApplicationCommand +=new OnApplicationCommandEventHandler(OnApplicationCommand);
        }

        #region IMdiChildWindow Members

        public void Activate()
        {
            if (IsInstanced())
            {
                _PackFormInstance.WindowState = FormWindowState.Maximized;
                _PackFormInstance.Visible = true;
            }

        }

        public bool CanClosed()
        {
            if (IsInstanced()) return true;
            return false;
        }

        public bool IsInstanced()
        {
            if (_PackFormInstance == null || _PackFormInstance.IsDisposed) return false;
            return true;
        }

        #endregion

        #region IWindow Members

        public void CloseWindow()
        {
            if (IsInstanced())
            {
                _PackFormInstance.Close();
                _PackFormInstance.Dispose();
            }
        }

        public bool Init()
        {
            try
            {
                if (_PackFormInstance == null || _PackFormInstance.IsDisposed)
                    _PackFormInstance = new PackForm();
                return true;
            }
            catch
            {
                return false;
            }

        }

        public bool OnApplicationCommand(object sender, string commandName, object[] commandParameters)
        {
            switch (commandName.Trim().ToLower())
            {
                case "showmdipackwindow":
                    ShowWindow();
                    break;
            }
            return false;
        }

        public void ShowWindow()
        {
            if (Init())
            {
                _PackFormInstance.MdiParent = Context.Current.MdiWindow.GetWindow();
                _PackFormInstance.WindowState = FormWindowState.Maximized;
                _PackFormInstance.Show();
            }
        }

        #endregion
    }

    public class DnUWindow : IMdiChildWindow
    {
        private DnUForm _DnUFormInstance;
        public DnUWindow()
        {
            Context.Current.OnApplicationCommand += new OnApplicationCommandEventHandler(OnApplicationCommand);
        }

        #region IMdiChildWindow Members

        public void Activate()
        {
            if (IsInstanced())
            {
                _DnUFormInstance.WindowState = FormWindowState.Maximized;
                _DnUFormInstance.Visible = true;
            }

        }

        public bool CanClosed()
        {
            if (IsInstanced()) return true;
            return false;
        }

        public bool IsInstanced()
        {
            if (_DnUFormInstance == null || _DnUFormInstance.IsDisposed) return false;
            return true;
        }

        #endregion

        #region IWindow Members

        public void CloseWindow()
        {
            if (IsInstanced())
            {
                _DnUFormInstance.Close();
                _DnUFormInstance.Dispose();
            }
        }

        public bool Init()
        {
            try
            {
                if (_DnUFormInstance == null || _DnUFormInstance.IsDisposed)
                    _DnUFormInstance = new DnUForm();
                return true;
            }
            catch
            {
                return false;
            }

        }

        public bool OnApplicationCommand(object sender, string commandName, object[] commandParameters)
        {
            switch (commandName.Trim().ToLower())
            {
                case "showmdidownloadwindow":
                    ShowWindow();
                    break;
            }
            return false;
        }

        public void ShowWindow()
        {
            if (Init())
            {
                _DnUFormInstance.MdiParent = Context.Current.MdiWindow.GetWindow();
                _DnUFormInstance.WindowState = FormWindowState.Maximized;
                _DnUFormInstance.Show();
            }
        }

        #endregion
    }
}
